package data.viewmodel_layer.account

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import data.network.ApiResponse
import data.network.AuthenticationResponse
import data.network.LoginRequest
import data.network.RetrofitBase
import data.network.UserResponse
import data.service.NewsService
import data.viewmodel_layer.reuse.BaseViewModelImpl
import data.viewmodel_layer.reuse.Resource
import retrofit2.Call

class AccountViewModel : BaseViewModelImpl() {
    private val _loginResult = MutableLiveData<Resource<ApiResponse<AuthenticationResponse>>>();
    val loginResult: LiveData<Resource<ApiResponse<AuthenticationResponse>>> = _loginResult

    private val _signUpResult = MutableLiveData<Resource<ApiResponse<UserResponse>>>()
    val signUpResult: LiveData<Resource<ApiResponse<UserResponse>>> = _signUpResult

    val apiService = RetrofitBase.apiService(NewsService::class.java)

    fun login(username: String, password: String) {
        performAction(_loginResult) {
            createLoginCall(LoginRequest(username, password))
        }
    }

    @Deprecated(message = "Maybe Not Use")
    fun signup(
        name: String, username: String, email: String,
        password: String, roles: Set<String> = setOf("USER")
    ) {
        // todo
    }


    private fun createLoginCall(request: LoginRequest):
            Call<ApiResponse<AuthenticationResponse>> {
        return apiService.login(request)
    }

    // todo
}

